import {
  BadRequestException,
  Body,
  Controller,
  Delete,
  Get,
  Param, ParseUUIDPipe,
  Patch,
  Post,
  Query,
  UseGuards,
} from '@nestjs/common';
import { ApiOkResponse, ApiOperation, ApiTags } from '@nestjs/swagger';
import {
  EvaluationComposeCreateDto,
  EvaluationComposeIndexDto,
  EvaluationComposeUpdateDto,
} from './evaluation-compose.dto';
import { EvaluationComposeService } from './evaluation-compose.service';
import { getPager } from "@/common/pager-response";
import { UserAuthGuard } from "@/common/auth/user-auth.guard";
import {
  EvaluationComposeIndexResult, EvaluationComposeShowResult
} from "@/module/evaluation-compose/evaluation-compose.result";
import { PageResult } from "common/interface";
import { ApiPaginatedOkResponse } from "@/common/pager-response/api-paginated-ok-response.decorator";
import { User } from "@/common/auth/user.decorator";
import { UserModel } from "@/module/user/user.model";

@Controller('/v1/evaluation-composes')
@ApiTags('EvaluationCompose')
@UseGuards(UserAuthGuard)
export class EvaluationComposeV1Controller {
  constructor(private readonly evaluationComposeService: EvaluationComposeService) {
  }

  @Get('/')
  @ApiOperation({ summary: '列表查询' })
  @ApiPaginatedOkResponse(EvaluationComposeIndexResult)
  async index(
    @Query() query: EvaluationComposeIndexDto,
    @User() user:UserModel,
  ): Promise<PageResult<EvaluationComposeIndexResult>> {
    const res = await this.evaluationComposeService.index(query, user.uuid);
    return getPager(res[0], res[1]);
  }

  @Get('/:uuid')
  @ApiOperation({ summary: '详情' })
  @ApiOkResponse({ type: EvaluationComposeShowResult })
  async show(
    @Param('uuid') uuid: string,
    @User() user:UserModel,
  ): Promise<EvaluationComposeShowResult> {
    const res = await this.evaluationComposeService.show(uuid, user.uuid);
    return res;
  }

  @Post('/')
  @ApiOperation({ summary: '新增' })
  async create(@Body() body: EvaluationComposeCreateDto, @User() user: UserModel): Promise<void> {
    await this.evaluationComposeService.create(body, user.uuid);
    return;
  }

  @Patch('/:uuid')
  @ApiOperation({ summary: '修改' })
  async update(
    @Body() body: EvaluationComposeUpdateDto,
    @Param('uuid', ParseUUIDPipe) uuid: string,
  ): Promise<void> {
    await this.evaluationComposeService.update(body, uuid);
    return;
  }

  @Delete('/:uuid')
  @ApiOperation({ summary: '删除' })
  async destroy(@Param('uuid', ParseUUIDPipe) uuid: string): Promise<void> {
    await this.evaluationComposeService.destroy(uuid);
    return;
  }
}
